import { Group } from '@/types/group'
import { defineStore } from 'pinia'
import { ref } from 'vue'

const defaultImage = '/static/global/missing-face.png'

const initGroup = {
  id: undefined,
  groupName: '',
  groupAvatar: '',
  description: '',
  masterUserId: undefined,
  masterUserName: '',
  memberList: [],
}

export const useGroupStore = defineStore(
  'group',
  () => {
    const group = ref<Group>({ ...initGroup })
    const groupList = ref<Group[]>([])

    const setGroup = (val: Group) => {
      group.value = val
    }

    const clearGroup = () => {
      group.value = { ...initGroup }
    }

    return {
      group,
      groupList,
      setGroup,
      clearGroup,
      defaultImage,
    }
  },
  {
    persist: true,
  },
)
